home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Development Tools & Languages / • Other Platforms / PCCTS 1.31 / testcpp / 4 / test.g < prev   
Encoding:
Text File  |  1995-03-10  |  952 b   |  46 lines  |  [TEXT/MPS ]

  1. /* This is test.g which tests a simple DLG-based scanner
  2.  * with user-defined tokens
  3.  */
  4.  
  5. /* Here, we use #tokdefs to define token types, but still let DLG do the
  6.  * lexing. ANTLR will not create a tokens.h file.
  7.  */
  8. #tokdefs "mytokens.h"
  9.  
  10. <<
  11. #include "DLGLexer.h"        /* include definition of DLGLexer.
  12.                              * This cannot be generated automatically because
  13.                              * ANTLR has no idea what you will call this file
  14.                              * with the DLG command-line options.
  15.                              */
  16.  
  17. typedef ANTLRCommonToken ANTLRToken;
  18.  
  19. int main()
  20. {
  21.     ANTLRToken aToken;
  22.     DLGFileInput in(stdin);
  23.     DLGLexer scan(&in,2000);
  24.     ANTLRTokenBuffer pipe(&scan);
  25.     scan.setToken(&aToken);
  26.     Expr parser(&pipe);
  27.     parser.init();
  28.  
  29.     parser.e();
  30.     return 0;
  31. }
  32. >>
  33.  
  34. #token "[\ \t\n]+"    <<skip();>>
  35.  
  36. class Expr {                /* Define a grammar class */
  37.  
  38. e    :    IDENTIFIER NUMBER "@"
  39.         <<fprintf(stderr, "text is %s,%s\n", $1->getText(), $2->getText());>>
  40.     ;
  41.  
  42. }
  43.  
  44. #token IDENTIFIER    "[a-z]+"
  45. #token NUMBER        "[0-9]+"
  46.